package com.jp.knowledge.view;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.model.FoundItem;

/**
 * Created by jiayen on 16/10/8.
 * 发现item
 */

public class FoundItemView extends RelativeLayout {
    private View view;
    private Context context;
    private ImageView icon;
    private TextView itemName;
    private TextView itemDesc;
//    private ImageView iconPhoto;
//    private TextView tip;
    private FoundItem item;
    public FoundItemView(Context context) {
        this(context,null);

    }

    public void setItem(FoundItem item) {
        this.item = item;
        setValue();
    }

    public FoundItemView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public FoundItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context=context;
        init();
    }

    /**
     * 设置描述文字
     * @param desc
     */
    public void setDescription(String desc){
        if(!TextUtils.isEmpty(desc)){
            itemDesc.setVisibility(View.VISIBLE);
            itemDesc.setText(desc);
        }else{
            itemDesc.setVisibility(View.GONE);
        }
    }


    /**
     * 设置描述文字
     */
    public void setDescriptionColor(int resId){
        itemDesc.setTextColor(resId);

    }

    private void init() {
        view = LayoutInflater.from(context).inflate(R.layout.activity_found_item,null);
        addView(view);
        icon = (ImageView) view.findViewById(R.id.icon);
        itemName = (TextView) view.findViewById(R.id.item_name);
        itemDesc = (TextView) view.findViewById(R.id.description);
//        iconPhoto= (ImageView) view.findViewById(R.id.icon_photo);
//        tip= (TextView) view.findViewById(R.id.icon_tip);
    }


    /**
     * 设置值
     */
    private void setValue(){
        if(item!=null){
            icon.setImageResource(item.getResId());
            itemName.setText(item.getName());
            String desc = item.getDescriton();

//            itemDesc.setTextColor(item.getDescriptionColor());
            if(!TextUtils.isEmpty(desc)){
                itemDesc.setVisibility(View.VISIBLE);
                itemDesc.setText(desc);
            }else{
                itemDesc.setVisibility(View.GONE);
            }

//            if(!item.isShowPhoto()){
//                iconPhoto.setVisibility(View.GONE);
//            }
//            if(!item.isShowTip()){
//                tip.setVisibility(View.GONE);
//            }

//            if(!item.isShowDescription()){
//                iconPhoto.setVisibility(View.GONE);
//                tip.setVisibility(View.GONE);
//                itemDesc.setVisibility(View.GONE);
//            }
        }
    }
}
